<template>
  <a-row>
    <div v-show="tableDataLists.length" class="total-table-container">
      <a-row>
        <a-table
          :columns="tableColumns"
          :data-source="tableDataLists"
          :pagination="false"
        >
        <template slot="uploadTime" slot-scope="text">
          {{timeFormatter(text)}}
        </template>
        </a-table>
      </a-row>
    </div>
    <a-empty v-show="!tableDataLists.length">
      <span slot="description" style="color:grey;">
        请输入搜索数据
      </span>
    </a-empty>
  </a-row>
</template>

<script>
import api from "@/server/ncCheckConfig";
import { columns } from "./tableConfig";
import ExportFile from "vue-json-excel";
import moment from "moment";

function buildJsonFields(lists) {
  let jsonFields = {};
  lists.forEach((item, index) => {
      jsonFields[item.title] = item.dataIndex;
  });
  return jsonFields;
}

export default {
  name: "HistoryOrderTable",
  props: {
    searchData: Object
  },
  components: {
    ExportFile
  },
  data() {
    return {
      userName: "",
      role: "",
      compId: "",
      tableColumns: columns,
      tableDataLists: [],
      isLoading: false,
      jsonFields: buildJsonFields(columns),

      // paginationOpt: {
      //   current: 1,
      //   pageNum: 1, // 默认当前页数
      //   pageSize: 10, // 默认当前页显示数据的大小
      //   total: 0, // 总数，必须先有
      //   showTotal: total => `共 ${total} 条`, // 显示总数
      // },
      iconLoading: false
    };
  },
  computed: {},
  watch: {
    searchData: function(newVal, oldVal) {
      let _this = this;
      _this.dataHandler();
    }
  },
  created() {},
  mounted() {
    
  },
  methods: {
    timeFormatter(time) {
      return moment((time-8*60*60)*1000).format(`YYYY-MM-DD HH:mm:ss`)
    },
    dataHandler() {
      if(this.searchData.classType == '数控系统') {
        if(localStorage.getItem('systemTableData')) {
          this.tableDataLists = JSON.parse(localStorage.getItem('systemTableData'))
        }
      } else if (this.searchData.classType == 'i/o') {
        if(localStorage.getItem('HIOTableData')) {
          this.tableDataLists = JSON.parse(localStorage.getItem('HIOTableData'))
        }
      } else if (this.searchData.classType == '伺服驱动') {
        if(localStorage.getItem('servoTableData')) {
          this.tableDataLists = JSON.parse(localStorage.getItem('servoTableData'))
        }
      } else {
        if(localStorage.getItem('motorTableData')) {
          this.tableDataLists = JSON.parse(localStorage.getItem('motorTableData'))
        }
      }
      this.tableDataLists.forEach((item) => {
        item.type = this.searchData.classType
      })
    },
    handleTableChange(pagination) {
      this.paginationOpt.current = pagination.current;
      this.paginationOpt.pageNum = pagination.current;
      this.getData()
    },
    formatType(type) {
      let curType =''
      switch(type) {
        case '数控系统':
          curType = 'macModel'
          break
        case 'i/o':
          curType = 'HIO'
          break
        case '伺服驱动':
          curType = 'servo'
          break
        case '电机':
          curType = 'macAxNum'
          break
        case '全部':
          curType = 'all'
          break
        default:
          break;
      }
      return curType
    }
  }
};
</script>

<style lang="css" scoped>
@import "./style.css";
.itemWrap {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: flex-start;
  align-items: center;
}

.itemWrap > .label {
  min-width: 90px;
  font-size: 16px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: #373737;
  text-align: right;
}

.itemWrap > .separator {
  padding: 0px 4px;
}

.itemWrap > .content {
  width: 100%;
  padding: 0px 1px;
}
.dialog-content {
  padding: 16px;
  height: 70vh;
  overflow: auto;
}
.dialog-footer {
  /* display: flex; */
  width: 100%;
  text-align: center;
}
.dialog-footer .footer-btn {
  margin-right: 16px;
}
</style>
